package com.zeng.bean.restmodel;

import com.zeng.annotation.restmodel.RestModel;
import com.zeng.util.GenUtils;
import lombok.Data;

import java.util.List;

/**
 * 数据表创建信息
 */
@Data
public class RestTableCreateParam {
    private String tableName;
    private List<RestTableFieldInfo> fields;
    private Class<?> clazz;

    public static RestTableCreateParam loadByTableClass(Class<?> clazz) {
        RestTableCreateParam param = new RestTableCreateParam();

        param.setClazz(clazz);
        String tableName = clazz.getSimpleName();
        RestModel annotation = clazz.getAnnotation(RestModel.class);
        if(annotation != null && !GenUtils.stringIsNullOrWhiteSpace(annotation.tableName())) {
            tableName = annotation.tableName();
        }
        param.setTableName(tableName);
        param.setFields(RestTableFieldInfo.loadByTableClass(clazz));

        return param;
    }
}
